import {
  Entity,
  Column,
  CreateDateColumn,
  ManyToOne,
  Relation,
  JoinColumn,
} from 'typeorm';
import { CommonEntity } from '~/common/entity/common.entity';
import { ApiProperty } from '@nestjs/swagger';

import { UserEntity } from '../../../user/user.entity';

@Entity({ name: 'sys_operation_log' })
export class OperationLogEntity extends CommonEntity {
  @Column({ nullable: true })
  @ApiProperty({ description: '操作模块' })
  module: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '操作类型' })
  actionType: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '消耗时间(毫秒)' })
  duration: number;

  @Column({ nullable: true })
  @ApiProperty({ description: '请求参数' })
  request: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '响应结果' })
  response: string;

  @ManyToOne(() => UserEntity, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'user_id' })
  user: Relation<UserEntity>;
}
